package com.kye.express.business.jd.goods_list_by_category.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author : Joe
 * @version : 1.0
 * @editor : Joe
 * @created : 29/01/2018
 * @updated : 29/01/2018
 * @description : <Description>
 * @update_reason : <UpdateReason>
 */

public class JDIntegralSelectModel implements Parcelable {

    public JDIntegralSelectModel(JDIntegralScopeType scopeType, boolean isSelected) {
        this.scopeType = scopeType;
        this.isSelected = isSelected;
    }

    private JDIntegralScopeType scopeType;
    private boolean isSelected;

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public JDIntegralSelectModel(JDIntegralScopeType scopeType) {
        this.scopeType = scopeType;
    }

    public JDIntegralScopeType getScopeType() {
        return scopeType;
    }

    public void setScopeType(JDIntegralScopeType scopeType) {
        this.scopeType = scopeType;
    }

    public JDIntegralSelectModel() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.scopeType == null ? -1 : this.scopeType.ordinal());
        dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }

    protected JDIntegralSelectModel(Parcel in) {
        int tmpScopeType = in.readInt();
        this.scopeType = tmpScopeType == -1 ? null : JDIntegralScopeType.values()[tmpScopeType];
        this.isSelected = in.readByte() != 0;
    }

    public static final Creator<JDIntegralSelectModel> CREATOR = new Creator<JDIntegralSelectModel>() {
        @Override
        public JDIntegralSelectModel createFromParcel(Parcel source) {
            return new JDIntegralSelectModel(source);
        }

        @Override
        public JDIntegralSelectModel[] newArray(int size) {
            return new JDIntegralSelectModel[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof JDIntegralSelectModel)) return false;

        JDIntegralSelectModel that = (JDIntegralSelectModel) o;

        if (isSelected != that.isSelected) return false;
        return scopeType == that.scopeType;
    }

    @Override
    public int hashCode() {
        int result = scopeType != null ? scopeType.hashCode() : 0;
        result = 31 * result + (isSelected ? 1 : 0);
        return result;
    }
}
